//
//  ProOrderSubSectionFooter.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/27.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "ProOrderSubSectionFooter.h"

@implementation ProOrderSubSectionFooter

- (void)fillFooterVithModel:(OrderListModel *)model {
    
    self.model = model;
    
    self.btn1.hidden = YES;
    self.btn2.hidden = YES;
    
    self.timeLab.text = model.uodCreateTime;
    self.totalLab.text = [NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.uodPayAmount]];
    
        
    for (int i = 0; i < model.bottomModel.btnArray.count; i ++) {
        
        if (i==0) {
            self.btn1.hidden = NO;
            self.btn1.tag = model.bottomModel.btnArray[0].btnAction;
            [self.btn1 setTitle:model.bottomModel.btnArray[0].btnTitle forState:UIControlStateNormal];
            [self fillBtn:self.btn1 WithType:model.bottomModel.btnArray[0].btnColorType];
        }
        
        if (i==1) {
            self.btn2.hidden = NO;
            self.btn2.tag = model.bottomModel.btnArray[1].btnAction;
            [self.btn2 setTitle:model.bottomModel.btnArray[1].btnTitle forState:UIControlStateNormal];
            [self fillBtn:self.btn2 WithType:model.bottomModel.btnArray[1].btnColorType];
        }
    }
}

- (void)fillBtn:(UIButton *)btn WithType:(NSInteger)type {
    
    if (type == 1) {
        
        [btn setTitleColor:UIColorHex(0xffffff) forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"rect_orange_big"] forState:UIControlStateNormal];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
            [btn pp_clipCorners:UIRectCornerAllCorners radius:15 border:0.1 color:UIColorHex(0xffffff)];
        });
        
    } else {
        
        [btn setTitleColor:UIColorHex(0xff4242) forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
            [btn pp_clipCorners:UIRectCornerAllCorners radius:15 border:1 color:UIColorHex(0xff4242)];
        });
    }
}

- (IBAction)btn1Action:(id)sender {
    if (self.ProOrderSubSectionFooterBlock) {
        self.ProOrderSubSectionFooterBlock(self.btn1.tag);
    }
}

- (IBAction)btn2Action:(id)sender {
    if (self.ProOrderSubSectionFooterBlock) {
        self.ProOrderSubSectionFooterBlock(self.btn2.tag);
    }
}

@end
